package com.mgface.zookeeper.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class DeleteNode {

	public static void main(String[] args) throws Exception {
		CuratorFramework client = CuratorFrameworkFactory.builder().connectString("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183")
				.sessionTimeoutMs(10_000)
				//.namespace("curator")//指定隔离命名空间
				.retryPolicy(new ExponentialBackoffRetry(100, 3))//baseSleepTimeMs：初始sleep时间
				.build();
		client.start();
		System.out.println("启动完毕...");
		System.out.println(client.getChildren().forPath("/"));
		String news = client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath("/curator/c1","c1".getBytes());
		System.out.println(new String(client.getData().forPath(news)));
		System.out.println(client.getChildren().forPath("/curator"));
		//强制删除，假如子节点存在的话
		client.delete().guaranteed().deletingChildrenIfNeeded().forPath("/curator");
		System.out.println(client.getChildren().forPath("/"));
	}

}
